package com.old.mapper;

import com.github.pagehelper.Page;
import com.old.annotation.AutoFill;
import com.old.dto.ActivityDTO;
import com.old.dto.ActivityQueryDTO;
import com.old.entity.Activity;
import com.old.enumeration.OperationType;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ActivityMapper {

    /**
     * 添加活动
     *
     * @param activityDTO
     */
    @AutoFill(OperationType.INSERT)
    @Options(useGeneratedKeys = true, keyProperty = "activityId") // 获取自增主键
    void addActivity(ActivityDTO activityDTO);

    // 查询活动
//    @Select("SELECT * FROM activity WHERE isShow = 1 order by createTime DESC")
    Page<Activity> activityListPage(ActivityQueryDTO activityQueryDTO);


    /**
     * 查询活动
     *
     * @param activityId
     */
    ActivityDTO findActivityById(Integer activityId);


    /**
     * 修改活动报名情况
     *
     * @param activityId
     */
    void updateJoinNum(@Param("activityId") Integer activityId,
                       @Param("joinNum") String joinNum);


    /**
     * 修改活动情况
     *
     * @param activity
     */
    void updateActivity(ActivityDTO activity);


    /**
     * 删除活动
     *
     * @param activityId
     */
    void deleteActivity(Integer activityId);

    List<Activity> list(Integer sort, String searchTerms);

    //查询用户参加的活动
    @Select("SELECT * FROM activity WHERE  isShow = 1 or isShow = 0  order by create_time DESC ")
//    @Select("SELECT * FROM activity WHERE JSON_CONTAINS(joinNum, JSON_ARRAY(#{authorId})) and isShow = 1 order by create_time DESC")
    Page<Activity> userJoinActivityListPage(ActivityQueryDTO activityQueryDTO);

    //审核活动
    @Update("UPDATE activity SET isShow = 1 WHERE activityId = #{activityId}")
    void updateActivityStatus(Integer activityId);

    void batchDeleteByIds(List<Integer> ids);
}
